package com.imooc.o2o.web.handle;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionAdvice {
	private static Logger logger = LoggerFactory.getLogger(ExceptionAdvice.class);

	@ExceptionHandler(RuntimeException.class)
	@ResponseBody
	public Map<String, Object> handle(RuntimeException e) {
		logger.error(e.toString());
		Map<String, Object> modelMap = new HashMap<>();
		modelMap.put("success", false);
		modelMap.put("errMsg", e.getMessage());
		return modelMap;
	}
}
